const path = require('path')
const ExtractTextWebpackPlugin = require('extract-text-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CleanWebpackPlugin =require('clean-webpack-plugin')

module.exports = {
    entry: {
        footprint: './src/js/index.js',
    },
    output: {
        filename: "[name].[chunkHash].js",
        path: path.resolve(__dirname, './dist/js')
    },
    externals: {
        jquery: "jQuery"
    },
    module: {
        rules: [
            {
                test: /\.css$/,
                use: ExtractTextWebpackPlugin.extract({
                    fallback: 'style-loader',
                    use: [
                        {
                            loader: "css-loader"
                        }
                    ]
                })
            },
            {
                test: /\.less$/i,
                use: ExtractTextWebpackPlugin.extract({
                    fallback: 'style-loader',
                    use: [
                        {
                            loader: "css-loader"
                        },
                        {
                            loader: "less-loader"
                        }
                    ]
                })
            },
            {
                test: /\.js$/,
                use: 'babel-loader',
                exclude: '/nodule_modules/'
            },
            {
                test: /\.(png|jpg|gif)$/,
                use: [
                    {
                        loader: "url-loader",
                        options: {
                            limit: 8000
                        }
                    }
                ]
            },
            {
                test: /\.(eot|woff2|woff|ttf|svg)$/,
                use: [
                    {
                        loader: 'url-loader',
                        options: {
                            publicPath: '',
                            outputPath: "html/",
                            useRelativePath:true
                        }
                    }
                ],
            }
        ]
    },
    plugins: [
        new CleanWebpackPlugin(['./dist/js']),
        new ExtractTextWebpackPlugin({
            filename: "../css/main.css",
            allChunks: true
        }),
        new HtmlWebpackPlugin({
            filename: "../index.html",
            template: "index.template.html"
        })
    ]
}
